<!DOCTYPE html>
<!--
这是一个入门模板页面。通过此页面从头开发新的项目。
该页面删除了所有链接，仅提供所需的标签。
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="x-ua-compatible" content="ie=edge">

  <title>SuperScope | 查寝</title>

  <!-- Font Awesome 图标 -->
  <link rel="stylesheet" href="../../static/plugins/fontawesome-free/css/all.min.css">
  <!-- 主题样式 -->
  <link rel="stylesheet" href="../../static/dist/css/adminlte.min.css">
  <!-- 离线 Google 字体: Source Sans Pro -->
  <link href="../../static/dist/css/google.css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
    <link rel="stylesheet" href="../../static/plugins/toastr/toastr.min.css">
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">

  <!-- 导航栏 -->
  <nav class="main-header navbar navbar-expand navbar-white navbar-light">
    <!-- 左侧导航栏链接 -->
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
      </li>
      <li class="nav-item d-none d-sm-inline-block">
        <a href="{{ url_for('monitorMain') }}" class="nav-link">主页</a>
      </li>
    </ul>

    <!-- 搜索表单 -->
    <form class="form-inline ml-3">
      <div class="input-group input-group-sm">
        <input class="form-control form-control-navbar" type="search" placeholder="搜索" aria-label="Search">
        <div class="input-group-append">
          <button class="btn btn-navbar" type="submit">
            <i class="fas fa-search"></i>
          </button>
        </div>
      </div>
    </form>

    <!-- 右侧导航栏链接 -->
    <ul class="navbar-nav ml-auto">
      <li class="nav-item dropdown">
        <a class="nav-link" data-toggle="dropdown" href="#">
          <i class="far fa-bell"></i>
          <span class="badge badge-warning navbar-badge">15</span>
        </a>
        <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
          <span class="dropdown-header">15 条通知</span>
          <div class="dropdown-divider"></div>
<a href="{{ url_for('chat') }}" class="dropdown-item">
            <i class="fas fa-envelope mr-2"></i> 4 条新消息
            <span class="float-right text-muted text-sm">3 分钟前</span>
          </a>
          <div class="dropdown-divider"></div>
          <a href="#" class="dropdown-item">
            <i class="fas fa-users mr-2"></i> 8 个好友请求
            <span class="float-right text-muted text-sm">12 小时前</span>
          </a>
          <div class="dropdown-divider"></div>
          <a href="#" class="dropdown-item">
            <i class="fas fa-file mr-2"></i> 3 个新报告
            <span class="float-right text-muted text-sm">2 天前</span>
          </a>
          <div class="dropdown-divider"></div>
          <a href="#" class="dropdown-item dropdown-footer">查看所有通知</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#" role="button"><i
            class="fas fa-th-large"></i></a>
      </li>
    </ul>
  </nav>
  <!-- /.navbar -->

  <!-- 主侧边栏容器 -->
  <aside class="main-sidebar sidebar-dark-primary elevation-4">
    <!-- 品牌 Logo -->
    <a href="index3.html" class="brand-link">
      <img src="../../static/dist/img/periscope.png" alt="AdminLTE Logo" class="brand-image img-circle elevation-3"
           style="opacity: .8">
      <span class="brand-text font-weight-light">SuperScope</span>
    </a>

    <!-- Sidebar -->
    <div class="sidebar">
      <!-- 侧边栏用户面板（可选） -->
      <div class="user-panel mt-3 pb-3 mb-3 d-flex">
        <div class="info">
          <a href="#" id="HelloUser" class="d-block">Alexander Pierce</a>
        </div>
      </div>

      <!-- 侧边栏菜单 -->
      <nav class="mt-2">
        <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
          <!-- 使用 .nav-icon 类添加图标，
               或使用 font-awesome 或其他任何图标字体库 -->
            <li class="nav-item">
            <a href="{{ url_for('monitorMain') }}" class="nav-link">
              <i class="nav-icon fas fa-th"></i>
              <p>
                首页
              </p>
            </a>
          </li>
            <li class="nav-item has-treeview">
            <a href="#" class="nav-link">
              <i class="nav-icon fas fa-tachometer-alt"></i>
              <p>
                监控
                <i class="right fas fa-angle-left"></i>
              </p>
            </a>
            <ul class="nav nav-treeview">
                <li class="nav-item">
                <a href="{{ url_for('infraRed') }}" class="nav-link">
                  <i class="far fa-circle nav-icon"></i>
                  <p>红外监控</p>
                </a>
              </li>
                <li class="nav-item">
                <a href="{{ url_for('temperatureAndHumidity') }}" class="nav-link">
                  <i class="far fa-circle nav-icon"></i>
                  <p>温湿度监控</p>
                </a>
              </li>
                <li class="nav-item">
                <a href="{{ url_for('door') }}" class="nav-link">
                  <i class="far fa-circle nav-icon"></i>
                  <p>门监控</p>
                </a>
              </li>
            </ul>
          </li>
            <li class="nav-item">
            <a href="{{ url_for('sleepCheck') }}" class="nav-link active">
              <i class="nav-icon fas fa-edit"></i>
              <p>
                查寝
              </p>
            </a>
          </li>
            <li class="nav-item">
            <a href="{{ url_for('personalInformation') }}" class="nav-link">
              <i class="nav-icon fas fa-file"></i>
              <p>
                个人信息
              </p>
            </a>
          </li>
            <li id="adminMaintenance" class="nav-item">
            <a href="{{ url_for('adminMaintenance') }}" class="nav-link">
              <i class="nav-icon fas fa-plus-square"></i>
              <p>
                管理员维护
              </p>
            </a>
          </li>
        </ul>
      </nav>
      <!-- /.sidebar-menu -->
    </div>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. 包含页面内容 -->
  <div class="content-wrapper">
    <!-- 内容标题（页面标题） -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">查寝</h1>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- 主体内容 -->
    <div class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-6">
            <div class="card">
              <div class="card-header">
                <h3 id="dormitoryInfo" class="card-title">寝室信息</h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-0">
                <table class="table table-hover text-nowrap">
                  <thead>
                    <tr>
                      <th>用户ID</th>
                      <th>用户姓名</th>
                      <th>用户电话</th>
                        <th>是否已查寝</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <td id="user1id"></td>
                      <td id="user1name"></td>
                      <td id="user1phone"></td>
                      <td><img id="user1check" src="../../static/dist/img/错.png" height="25" width="25"></td>
                    </tr>
                  <tr>
                      <td id="user2id"></td>
                      <td id="user2name"></td>
                      <td id="user2phone"></td>
                      <td><img id="user2check" src="../../static/dist/img/对.png" height="25" width="25"></td>
                    </tr>
                  <tr>
                      <td id="user3id"></td>
                      <td id="user3name"></td>
                      <td id="user3phone"></td>
                      <td><img id="user3check" src="../../static/dist/img/对.png" height="25" width="25"></td>
                    </tr>
                  <tr>
                      <td id="user4id"></td>
                      <td id="user4name"></td>
                      <td id="user4phone"></td>
                      <td><img id="user4check" src="../../static/dist/img/对.png" height="25" width="25"></td>
                    </tr>
                  </tbody>
                </table>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <div class="col-md-3">
            <div class="card card-success">
              <div class="card-header">
                <h3 class="card-title">打卡</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-minus"></i>
                  </button>
                </div>
                <!-- /.card-tools -->
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <p id="time"><b></b></p>
                  <div id="time2">
                      <p><b>你已经完成打卡！</b></p>
                  </div>
                  <div id="time3">
                      <p><b>你还没有完成打卡！</b></p>
                      <button type="button" id="inDormitory" class="btn-flat btn-success btn-block">我已回寝</button>
                  </div>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- 控制侧边栏内容在这里 -->
    <div class="p-3">
      <h5>标题</h5>
      <p>侧边栏内容</p>
    </div>
  </aside>
  <!-- /.control-sidebar -->

  <!-- Main Footer -->
  <footer class="main-footer">
    <!-- To the right -->
    <div class="float-right d-none d-sm-inline">
      任何你想要的
    </div>
    <!-- Default to the left -->
    <strong>Copyright &copy; 2021 <a href="#">SuperScope.com</a>.</strong> 保留所有权利。
  </footer>
</div>
<!-- ./wrapper -->

<!-- 载入脚本 -->

<!-- jQuery -->
<script src="../../static/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../../static/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="../../static/dist/js/adminlte.min.js"></script>
<script src="../../static/plugins/toastr/toastr.min.js"></script>
<script type = "text/javascript" >
    var userid;
    var dormitoryId;
    $(function (){
        $.ajax({
            url: '/getSession',
            type: 'POST',
            data: {},
            dataType: 'json',
            success: function (data) {
                if(data['admin'] === 1){
                    document.getElementById("HelloUser").innerText = "你好! 管理员 " + data['username'];
                }
                else{
                    userid = data['userid'];
                    dormitoryId = data['dormitoryId'];
                    console.log(data);
                    document.getElementById("HelloUser").innerText = "你好! 学生 " + data['username'];
                    document.getElementById("adminMaintenance").hidden = true;
                    document.getElementById("dormitoryInfo").innerText = "寝室信息——" + data['dormitoryId'];
                    document.getElementById("user1id").innerText = data['user1Id'];
                    document.getElementById("user2id").innerText = data['user2Id'];
                    document.getElementById("user3id").innerText = data['user3Id'];
                    document.getElementById("user4id").innerText = data['user4Id'];
                    document.getElementById("user1name").innerText = data['user1Name'];
                    document.getElementById("user2name").innerText = data['user2Name'];
                    document.getElementById("user3name").innerText = data['user3Name'];
                    document.getElementById("user4name").innerText = data['user4Name'];
                    document.getElementById("user1phone").innerText = data['user1Phone'];
                    document.getElementById("user2phone").innerText = data['user2Phone'];
                    document.getElementById("user3phone").innerText = data['user3Phone'];
                    document.getElementById("user4phone").innerText = data['user4Phone'];
                    document.getElementById("time").innerText = "日期：" + new Date().toDateString();
                    if(data['isInDormitory'] === 1)
                        document.getElementById("time3").hidden = true;
                    else{
                        document.getElementById("time2").hidden = true;
                    }
                    if(data['isInDormitory1'] === 1)
                        document.getElementById("user1check").setAttribute("src","../../static/dist/img/对.png");
                    else
                        document.getElementById("user1check").setAttribute("src","../../static/dist/img/错.png");
                    if(data['isInDormitory2'] === 1)
                        document.getElementById("user2check").setAttribute("src","../../static/dist/img/对.png");
                    else
                        document.getElementById("user2check").setAttribute("src","../../static/dist/img/错.png");
                    if(data['isInDormitory3'] === 1)
                        document.getElementById("user3check").setAttribute("src","../../static/dist/img/对.png");
                    else
                        document.getElementById("user3check").setAttribute("src","../../static/dist/img/错.png");
                    if(data['isInDormitory4'] === 1)
                        document.getElementById("user4check").setAttribute("src","../../static/dist/img/对.png");
                    else
                        document.getElementById("user4check").setAttribute("src","../../static/dist/img/错.png");
                }
            }
        })
    });
    $('#inDormitory').on('click',function() {
        var data = {
            data:JSON.stringify({
                'userid':userid,
                'dormitoryId':dormitoryId
            }),
        }
        //提交
        $.ajax({
            type:"POST",
            dataType:"json",
            url:"/monitor/sleepCheck",
            data: data,
            success :function (result){
                toastr.success("打卡成功！");
                setTimeout(function (){window.location.reload();},1000)
            },
            error:function (result){
                toastr.error("未知错误！请联系管理员");
            }
        });
  })

</script>
</body>
</html>
